﻿using System;
using NDBGen.Descriptors;

namespace NDBGen.Plugins
{
    public abstract class SnippetGeneratorBase<TDescriptor, TPluginData> : IGenerator<TDescriptor>
        where TDescriptor: IDescriptor
        where TPluginData : IPluginData
    {
        protected Boolean InitCalled { get; set; }

        protected TDescriptor Descriptor { get; private set; }

        protected ParsedInput ParsedInput { get { return this.PluginData.ParsedInput; } }

        protected virtual void Init(IPluginData pluginData, TDescriptor descriptor)
        {
            this.Descriptor = descriptor;
            this.PluginData = (TPluginData)pluginData;

            this.InitCalled = true;
        }

        protected TPluginData PluginData { get; private set; }

        #region [ IGenerator<TDescriptor> Members ]

        void IGenerator<TDescriptor>.Init(IPluginData initData, TDescriptor descriptor)
        {
            this.Init(initData, descriptor);
        }
        
        #endregion

        #region [ IGenerator Members ]

        ParsedInput IGenerator.ParsedInput
        {
            get { return this.ParsedInput; }
        }

        IPluginData IGenerator.PluginData
        {
            get { return this.PluginData; }
        }

        #endregion
    }
}